import os
from functools import wraps
import uuid


def dir_name(module_name):
    return os.path.dirname(os.path.abspath(module_name))


def ascii_info(lines, min_size=None):
    if not isinstance(lines, list):
        lines = [lines]

    size = len(max(lines, key=len)) + 4

    if min_size is not None and size < min_size:
        size = min_size

    size_e = size - 2
    size_t = size - 3
    print '\n{{:#<{0}}}\n#{{:<{1}}}#'.format(size, size_e).format('', '')

    for line in lines:
        print '# {{:<{0}}}#'.format(size_t).format(line)

    print '#{{:<{0}}}#\n{{:#<{1}}}'.format(size_e, size).format('', '')


def unique_id():
    return str(uuid.uuid4())


def accept(status=None):
    if not status: status = ['ALL']

    def decorator(func):
        @wraps(func)
        def wrapper(*args, **kwargs):
            if len(args) == 1:
                data_packet = args[0]
            else:
                data_packet = args[1]
            data_packet_status = data_packet['status']
            if data_packet_status in status:
                return func(*args, **kwargs)
            else:
                return data_packet
        return wrapper
    return decorator
